package com.vgemv.jsutilitysdkdemo.module.Page;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.vgemv.jsutilitysdk.Menu.JsMenuFragment.JsMenuFragment.JsMenuFragment;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVm;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemView.JsMenuItemView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVmDefault;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewAdapter;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewBasicCallback;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewRefreshCallback;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewVm;
import com.vgemv.jsutilitysdk.Page.JsPageGroupView.JsPageGroupView;
import com.vgemv.jsutilitysdk.Page.JsPageGroupView.JsPageGroupViewCallback;
import com.vgemv.jsutilitysdk.Page.JsPageGroupView.JsPageGroupViewVm;
import com.vgemv.jsutilitysdk.Request.JsRequestManager.JsRequestDictionaryCallback;
import com.vgemv.jsutilitysdk.Request.JsRequestManager.JsRequestManager;
import com.vgemv.jsutilitysdk.geometry.JsGeometryManager;
import com.vgemv.jsutilitysdk.log.JsLogManager;
import com.vgemv.jsutilitysdkdemo.module.List.Chat.ChatItemView;
import com.vgemv.jsutilitysdkdemo.module.List.Chat.ChatItemViewVm;
import com.vgemv.jsutilitysdkdemo.module.List.Chat.ChatModel;
import com.vgemv.jsutilitysdkdemo.module.List.ExtendContent.ExtendContentItemView;
import com.vgemv.jsutilitysdkdemo.module.List.ExtendContent.ExtentContentItemViewVm;
import com.vgemv.jsutilitysdkdemo.module.List.ExtendContent.ExtentContentModel;
import com.vgemv.jsutilitysdkdemo.module.List.WordLive.WordLiveModel;
import com.vgemv.jsutilitysdkdemo.module.List.WordLive.WordLiveView;
import com.vgemv.jsutilitysdkdemo.module.List.WordLive.WordLiveViewVm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


public class PageActivity extends AppCompatActivity {


    private View mv_mainMenuContainer;

    private RelativeLayout mrl_root;
    private ArrayList<JsMenuItemVm> mal_comment = new ArrayList<>();
    private ArrayList<JsMenuItemVm> mal_wordLive = new ArrayList<>();
    private ArrayList<JsMenuItemVm> mal_extentContent = new ArrayList<>();

    private JsMenuFragment MenuView_comment;
    private JsMenuFragment MenuView_wordLive;
    private JsMenuFragment MenuView_extentContent;

    private String lastCommentId = "0";
    private String lastWordLiveId = "0";
    private String lastExtentContentId = "0";

    private String pageSize = "1";
    private PageActivityVm mvm = new PageActivityVm();
    private JsPageGroupView mPageGroupView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        JsRequestManager.sharedInstance().serverAddress = "http://1.14.158.158";
        setupUi();
    }


    public void setupUi() {
        //root view
        {
            mrl_root = new RelativeLayout(this);
            mrl_root.setId(View.generateViewId());
            setContentView(mrl_root);
        }

        //MainMenuContainer;
        {
                mv_mainMenuContainer = new FrameLayout(this);
                mv_mainMenuContainer.setId(View.generateViewId());
                mrl_root.addView(mv_mainMenuContainer);
                {
                    //MainMenu
                    JsMenuFragment fragment = new JsMenuFragment();
                    fragment.moveToParentView(this, mv_mainMenuContainer);

                    final int top = (mvm.mi_mainMenuHeight - mvm.mi_mainMenuItemHeight)/2;
                    int buttonCount = 3;

                    final int cellCellSpacing = (JsGeometryManager.getScreenSizeInPixel(this).getWidth() - mvm.mi_mainMenuItemWidth * buttonCount) / ((buttonCount -1) + 2 * mvm.mi_cellParantPaddingScale);
                    final int cellParentSpacing = cellCellSpacing * mvm.mi_cellParantPaddingScale;

                    fragment.mBasicCallback = new JsMenuViewBasicCallback() {
                        @Override
                        public JsMenuViewAdapter jsMenuViewSetAdapter(JsMenuView menuView) {
                            return null;
                        }

                        @Override
                        public void jsMenuItemViewWillDisplay(RecyclerView.ViewHolder viewHolder, int position) {

                        }

                        @Override
                        public Rect jsMenuViewSetItemOffset(JsMenuView fragment, int index) {
                            Rect rect = new Rect();
                            if(index == 0) {
                                //第一个
                                rect.top = top;
                                rect.left = cellParentSpacing;
                                rect.right = cellCellSpacing/2;
                            }
                            else if(index == fragment.vms().size() - 1) {
                                //最后一个
                                rect.top = top;
                                rect.left = cellCellSpacing/2;
                                rect.right = cellParentSpacing;
                            }
                            else {
                                //中间的
                                rect.top = top;
                                rect.left = cellCellSpacing/2;
                                rect.right = cellCellSpacing/2;
                            }
                            return rect;
                        }

                        @Override
                        public JsMenuViewVm jsMenuViewSetVm(JsMenuView fragment) {
                            JsMenuViewVm vm = new JsMenuViewVm();
                            vm.mi_layoutStyle = 1;
                            vm.mColor_background = Color.argb(255,200,100,100);
                            vm.mI_initialSelectedIndex = 0;
                            return vm;
                        }
                        @Override
                        public JsMenuItemView jsMenuViewCreateItemView(JsMenuView fragment, Context context) {
                            return null;
                        }

                        @Override
                        public void jsMenuViewAfterCreateView(JsMenuView fragment) {

                        }

                        @Override
                        public ArrayList<JsMenuItemVm> jsMenuViewSetDatasource() {
                            ArrayList<JsMenuItemVm> al = new ArrayList<>();
                            {
                                JsMenuItemVm vm = new JsMenuItemVmDefault(null,"图文直播",null,mvm.mi_mainMenuItemWidth,mvm.mi_mainMenuItemHeight);
                                al.add(vm);
                            }
                            {
                                JsMenuItemVm vm = new JsMenuItemVmDefault(null,"聊天",null,mvm.mi_mainMenuItemWidth,mvm.mi_mainMenuItemHeight);
                                al.add(vm);
                            }
                            {
                                JsMenuItemVm vm = new JsMenuItemVmDefault(null,"相关报道",null,mvm.mi_mainMenuItemWidth,mvm.mi_mainMenuItemHeight);
                                al.add(vm);
                            }
                            return al;
                        }

                        @Override
                        public void jsMenuViewClickItem(JsMenuView fragment, int i, JsMenuItemVm model) {
                            JsLogManager.logc_d("MenuActivity/jsMenuViewClickItem","index is %d",i);
                            mPageGroupView.choosePage(i);
                        }
                    };
                }
        }

        //PageGroupView
        {
            mPageGroupView = new JsPageGroupView(this, new JsPageGroupViewCallback() {
                @Override
                public JsPageGroupViewVm jsPageGroupViewSetVm(JsPageGroupView groupView) {
                    JsPageGroupViewVm vm = new JsPageGroupViewVm();
                    vm.backgroundColor = Color.argb(255,100,200,100);
                    return null;
                }

                @Override
                public void jsPageGroupViewSetPageViewContent(JsPageGroupView groupView, FrameLayout frameLayout, int index) {

                }

                @Override
                public void jsPageGroupViewScrollToNewPage(JsPageGroupView groupView, FrameLayout pageViewContainer, int index) {

                }
            });
            mPageGroupView.setId(View.generateViewId());
            mrl_root.addView(mPageGroupView);



            int height = JsGeometryManager.getScreenSizeInPixel().getHeight() - mvm.mi_mainMenuHeight;
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height);
            lp.addRule(RelativeLayout.BELOW,mv_mainMenuContainer.getId());
            lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            mPageGroupView.setLayoutParams(lp);

        }

        //WordLive
        {
            JsMenuFragment fragment = new JsMenuFragment();
                MenuView_wordLive = fragment;
                View wordLiveView = mPageGroupView.pageForIndex(0);
                fragment.moveToParentView(this, wordLiveView);

                final int padding = WordLiveViewVm.itemViewParentHPadding;

                fragment.mBasicCallback = new JsMenuViewBasicCallback() {
                    @Override
                    public JsMenuViewAdapter jsMenuViewSetAdapter(JsMenuView menuView) {
                        return null;
                    }

                    @Override
                    public void jsMenuItemViewWillDisplay(RecyclerView.ViewHolder viewHolder, int position) {

                    }

                    @Override
                    public Rect jsMenuViewSetItemOffset(final JsMenuView fragment, int index) {
                        Rect rect = new Rect();
                        if(index == 0) {
                            rect.top = padding;
                            rect.left = padding;
                            rect.right = padding;
                            rect.bottom = 0;
                        }
                        else if(index == fragment.vms().size() - 1) {
                            rect.top = padding;
                            rect.left = padding;
                            rect.right = padding;
                            rect.bottom = padding;
                        }
                        else {
                            rect.top = padding;
                            rect.left = padding;
                            rect.right = padding;
                            rect.bottom = 0;
                        }
                        return rect;
                    }

                    @Override
                    public JsMenuViewVm jsMenuViewSetVm(JsMenuView fragment) {
                        JsMenuViewVm vm = new JsMenuViewVm();
                        vm.mi_layoutStyle = 2;
                        vm.mColor_background = Color.argb(255,200,200,200);
                        vm.mb_enableRefreshAndLoadmore = true;
                        return vm;
                    }
                    @Override
                    public JsMenuItemView jsMenuViewCreateItemView(JsMenuView fragment, Context context) {
                        WordLiveView chatItemView = new WordLiveView(context);
                        return chatItemView;
                    }

                    @Override
                    public void jsMenuViewAfterCreateView(JsMenuView fragment) {

                    }

                    @Override
                    public ArrayList<JsMenuItemVm> jsMenuViewSetDatasource() {
                        return mal_wordLive;
                    }

                    @Override
                    public void jsMenuViewClickItem(JsMenuView fragment, int i, JsMenuItemVm model) {
                        JsLogManager.logc_d("MenuActivity/jsMenuViewClickItem","index is %d",i);
                    }
                };
                fragment.mRefreshCallback = new JsMenuViewRefreshCallback() {
                    @Override
                    public void onRefresh(final JsMenuView fragment) {
                        loadFirstPageWordLive();

                    }

                    @Override
                    public void onLoadMore(final JsMenuView fragment, int loadedPage) {
                        loadMorePageWordLive();
                    }
                };

        }

        //Chat
        {
            JsMenuFragment fragment = new JsMenuFragment();
            MenuView_comment = fragment;
            View commetView = mPageGroupView.pageForIndex(1);
            fragment.moveToParentView(this, commetView);

            final int padding = WordLiveViewVm.itemViewParentHPadding;

            fragment.mBasicCallback = new JsMenuViewBasicCallback() {
                @Override
                public JsMenuViewAdapter jsMenuViewSetAdapter(JsMenuView menuView) {
                    return null;
                }

                @Override
                public void jsMenuItemViewWillDisplay(RecyclerView.ViewHolder viewHolder, int position) {

                }

                @Override
                public Rect jsMenuViewSetItemOffset(final JsMenuView fragment, int index) {
                    Rect rect = new Rect();
                    if(index == 0) {
                        rect.top = padding;
                        rect.left = padding;
                        rect.right = padding;
                        rect.bottom = 0;
                    }
                    else if(index == fragment.vms().size() - 1) {
                        rect.top = padding;
                        rect.left = padding;
                        rect.right = padding;
                        rect.bottom = padding;
                    }
                    else {
                        rect.top = padding;
                        rect.left = padding;
                        rect.right = padding;
                        rect.bottom = 0;
                    }
                    return rect;
                }

                @Override
                public JsMenuViewVm jsMenuViewSetVm(JsMenuView fragment) {
                    JsMenuViewVm vm = new JsMenuViewVm();
                    vm.mi_layoutStyle = 2;
                    vm.mColor_background = Color.argb(255,200,200,200);
                    vm.mb_enableRefreshAndLoadmore = true;
                    return vm;
                }
                @Override
                public JsMenuItemView jsMenuViewCreateItemView(JsMenuView fragment, Context context) {
                    ChatItemView chatItemView = new ChatItemView(context);
                    return chatItemView;
                }

                @Override
                public void jsMenuViewAfterCreateView(JsMenuView fragment) {

                }

                @Override
                public ArrayList<JsMenuItemVm> jsMenuViewSetDatasource() {
                    return mal_comment;
                }

                @Override
                public void jsMenuViewClickItem(JsMenuView fragment, int i, JsMenuItemVm model) {
                    JsLogManager.logc_d("MenuActivity/jsMenuViewClickItem","index is %d",i);
                }
            };
            fragment.mRefreshCallback = new JsMenuViewRefreshCallback() {
                @Override
                public void onRefresh(final JsMenuView fragment) {
                    loadFirstPageComment();

                }

                @Override
                public void onLoadMore(final JsMenuView fragment, int loadedPage) {
                    loadMorePageComment();
                }
            };
        }

        //ExtentContent
        {
            JsMenuFragment fragment = new JsMenuFragment();
            MenuView_extentContent = fragment;
            View extentContentView = mPageGroupView.pageForIndex(2);
            fragment.moveToParentView(this, extentContentView);

            final int padding = ExtentContentItemViewVm.itemViewParentHPadding;

            fragment.mBasicCallback = new JsMenuViewBasicCallback() {
                @Override
                public Rect jsMenuViewSetItemOffset(final JsMenuView fragment, int index) {
                    Rect rect = new Rect();
                    if(index == 0) {
                        rect.top = padding;
                        rect.left = padding;
                        rect.right = padding;
                        rect.bottom = 0;
                    }
                    else if(index == fragment.vms().size() - 1) {
                        rect.top = padding;
                        rect.left = padding;
                        rect.right = padding;
                        rect.bottom = padding;
                    }
                    else {
                        rect.top = padding;
                        rect.left = padding;
                        rect.right = padding;
                        rect.bottom = 0;
                    }
                    return rect;
                }

                @Override
                public JsMenuViewAdapter jsMenuViewSetAdapter(JsMenuView menuView) {
                    return null;
                }

                @Override
                public void jsMenuItemViewWillDisplay(RecyclerView.ViewHolder viewHolder, int position) {

                }

                @Override
                public JsMenuViewVm jsMenuViewSetVm(JsMenuView fragment) {
                    JsMenuViewVm vm = new JsMenuViewVm();
                    vm.mi_layoutStyle = 2;
                    vm.mColor_background = Color.argb(255,200,200,200);
                    vm.mb_enableRefreshAndLoadmore = true;
                    return vm;
                }
                @Override
                public JsMenuItemView jsMenuViewCreateItemView(JsMenuView fragment, Context context) {
                    ExtendContentItemView chatItemView = new ExtendContentItemView(context);
                    return chatItemView;
                }



                @Override
                public void jsMenuViewAfterCreateView(JsMenuView fragment) {

                }

                @Override
                public ArrayList<JsMenuItemVm> jsMenuViewSetDatasource() {
                    return mal_extentContent;
                }

                @Override
                public void jsMenuViewClickItem(JsMenuView fragment, int i, JsMenuItemVm model) {
                    JsLogManager.logc_d("MenuActivity/jsMenuViewClickItem","index is %d",i);
                }
            };
            fragment.mRefreshCallback = new JsMenuViewRefreshCallback() {
                @Override
                public void onRefresh(final JsMenuView fragment) {
                    loadFirstPageExtentContent();

                }

                @Override
                public void onLoadMore(final JsMenuView fragment, int loadedPage) {
                    loadMorePageExtentContent();
                }
            };
        }

        loadFirstPageWordLive();
        loadFirstPageComment();
        loadFirstPageExtentContent();
    }

    public void loadFirstPageComment() {
        lastCommentId = "0";
        loadComments("27", pageSize, lastCommentId, new JsRequestDictionaryCallback() {
            @Override
            public void onRequestResponse(int responseCode, Map resultObject, String detailInfo) {
                JsLogManager.logc_d("WordLiveActivity/onCreate",detailInfo);
                if(resultObject != null) {
                    mal_comment.clear();
                    ArrayList<HashMap> arrayList = (ArrayList) resultObject.get("liveRoomDiscuss");
                    if(arrayList != null && arrayList.size() > 0) {
                        for (int i = 0; i < arrayList.size(); i++) {
                            HashMap map = (HashMap) arrayList.get(i);
                            ChatModel model = new ChatModel(map);
                            ChatItemViewVm vm = new ChatItemViewVm();
                            vm.setModel(model);
                            mal_comment.add(vm);
                        }
                        ChatItemViewVm lastVm = (ChatItemViewVm) mal_comment.get(mal_comment.size() - 1);
                        lastCommentId = lastVm.getModel().discussID.toString();
                        MenuView_comment.reloadData();
                        MenuView_comment.finishRefresh(true, arrayList.size()>0);
                    }
                    else {
                        MenuView_comment.reloadData();
                        MenuView_comment.finishRefresh(true, false);
                    }
                }
                else {
                    MenuView_comment.finishRefresh(false,false);
                }
            }
        });
    }

    public void loadMorePageComment() {
        loadComments("27", pageSize, lastCommentId, new JsRequestDictionaryCallback() {
            @Override
            public void onRequestResponse(int responseCode, Map resultObject, String detailInfo) {
                JsLogManager.logc_d("WordLiveActivity/onCreate",detailInfo);
                if(resultObject != null) {
                    ArrayList<HashMap> arrayList = (ArrayList) resultObject.get("contextCornerRadius");
                    if(arrayList != null && arrayList.size() > 0) {
                        for (int i = 0; i < arrayList.size(); i++) {
                            HashMap map = (HashMap) arrayList.get(i);
                            ChatModel model = new ChatModel(map);
                            ChatItemViewVm vm = new ChatItemViewVm();
                            vm.setModel(model);
                            mal_comment.add(vm);
                        }
                        ChatItemViewVm lastVm = (ChatItemViewVm) mal_comment.get(mal_comment.size() - 1);
                        lastCommentId = lastVm.getModel().discussID.toString();
                        MenuView_comment.reloadData();
                        MenuView_comment.finishRefresh(true, arrayList.size()>0);
                    }
                    else {
                        MenuView_comment.finishRefresh(true,false);
                    }
                }
                else {
                    MenuView_comment.finishRefresh(false,false);
                }

            }
        });
    }

    //检查所有数据的日期,当前第一个显示,其余不显示.
    private void tagWordLiveArrayDate() {
        String currentDate = null;
        for(int i = 0;i<mal_wordLive.size();i++) {
            WordLiveViewVm vm = (WordLiveViewVm)mal_wordLive.get(i);
            if(i == 0) {
                currentDate = vm.model.publishDate;
                vm.mb_isShowDate = true;
            }
            else {
                if(vm.model.publishDate.equals(currentDate)) {
                    vm.mb_isShowDate = false;
                }
                else {
                    vm.mb_isShowDate = true;
                    currentDate = vm.model.publishDate;
                }
            }
        }
    }








    public static void loadComments(String roomId, String pageSize, String nextPageId, JsRequestDictionaryCallback callback) {
        String urlString = String.format("%s/%s", JsRequestManager.sharedInstance().serverAddress,"api/liveRoomDiscuss/listLiveRoomDiscuss.action");

        Map<String,String> map_param = new HashMap();
        map_param.put("roomID",roomId);
        map_param.put("nextPageID",nextPageId);
        map_param.put("pagesize",pageSize);

        JsRequestManager.sharedInstance().getRequest(urlString, map_param, callback);
    }

    public void loadFirstPageWordLive() {

        loadWordLiveContents("27", pageSize, "0","0", new JsRequestDictionaryCallback() {
            @Override
            public void onRequestResponse(int responseCode, Map resultObject, String detailInfo) {
                JsLogManager.logc_d("WordLiveActivity/onCreate",detailInfo);
                if(resultObject != null) {
                    mal_wordLive.clear();
                    ArrayList<HashMap> arrayList = (ArrayList) resultObject.get("list");
                    for (Map<String,Object> map : arrayList) {
                        WordLiveModel model = new WordLiveModel(map);
                        WordLiveViewVm vm = new WordLiveViewVm();

                        vm.model = model;
                        mal_wordLive.add(vm);
                    }
                    WordLiveViewVm lastVm = (WordLiveViewVm)mal_wordLive.get(mal_wordLive.size()-1);
                    lastWordLiveId = lastVm.model.id.toString();
                    tagWordLiveArrayDate();
                    MenuView_wordLive.reloadData();
                    MenuView_wordLive.finishRefresh(true,arrayList.size()>0);

                }
                else {
                    MenuView_wordLive.finishRefresh(false,false);
                }
            }
        });
    }

    public void loadMorePageWordLive() {
        loadWordLiveContents("27", pageSize, lastWordLiveId,"0", new JsRequestDictionaryCallback() {
            @Override
            public void onRequestResponse(int responseCode, Map resultObject, String detailInfo) {
                JsLogManager.logc_d("WordLiveActivity/onCreate",detailInfo);
                if(resultObject != null) {
                    ArrayList<HashMap> arrayList = (ArrayList) resultObject.get("list");
                    for (int i = 0; i < arrayList.size(); i++) {
                        HashMap map = (HashMap) arrayList.get(i);
                        WordLiveModel model = new WordLiveModel(map);
                        WordLiveViewVm vm = new WordLiveViewVm();

                        vm.model = model;
                        mal_wordLive.add(vm);
                    }

                    WordLiveViewVm lastVm = (WordLiveViewVm)mal_wordLive.get(mal_wordLive.size()-1);
                    lastWordLiveId = lastVm.model.id.toString();

                    tagWordLiveArrayDate();
                    MenuView_wordLive.reloadData();
                    MenuView_wordLive.finishRefresh(true,arrayList.size()>0);

                }
                else {
                    MenuView_wordLive.finishRefresh(false,false);
                }

            }
        });
    }
    public static void loadWordLiveContents(String roomId,String pageSize,String nextPageId,String order, JsRequestDictionaryCallback callback ) {
        String urlString = String.format("%s/%s?roomId=%s", JsRequestManager.sharedInstance().serverAddress,"apiserver/listWordLiveContent.action",roomId);
        HashMap map_param = new HashMap();
        map_param.put("roomID",roomId);
        map_param.put("nextPageID",nextPageId);
        map_param.put("pagesize",pageSize);
        map_param.put("order",order);
        JsRequestManager.sharedInstance().postReqeustByJson(urlString, map_param,callback);
    }


    public void loadFirstPageExtentContent() {
        lastExtentContentId = "0";
        loadExtendContent("27", pageSize, lastExtentContentId, new JsRequestDictionaryCallback() {
            @Override
            public void onRequestResponse(int responseCode, Map resultObject, String detailInfo) {
                JsLogManager.logc_d("WordLiveActivity/onCreate", detailInfo);
                if (resultObject != null) {
                    mal_extentContent.clear();
                    ArrayList<HashMap> arrayList = (ArrayList) resultObject.get("list");
                    if (arrayList != null && arrayList.size() > 0) {
                        for (Map<String, Object> map : arrayList) {
                            ExtentContentModel model = new ExtentContentModel(map);
                            ExtentContentItemViewVm vm = new ExtentContentItemViewVm();
                            vm.model = model;
                            mal_extentContent.add(vm);
                        }
                        ExtentContentItemViewVm lastVm = (ExtentContentItemViewVm) mal_extentContent.get(mal_extentContent.size() - 1);
                        lastExtentContentId = lastVm.model.id.toString();
                        MenuView_extentContent.reloadData();
                        MenuView_extentContent.finishRefresh(true, arrayList.size()>0);

                    }
                    else {
                        MenuView_extentContent.reloadData();
                        MenuView_extentContent.finishRefresh(true, false);
                    }
                }
                else {
                    MenuView_extentContent.finishRefresh(false,false);
                }
            }
        });
    }

    public void loadMorePageExtentContent() {
        loadExtendContent("27", pageSize, lastExtentContentId, new JsRequestDictionaryCallback() {
            @Override
            public void onRequestResponse(int responseCode, Map resultObject, String detailInfo) {
                JsLogManager.logc_d("WordLiveActivity/onCreate",detailInfo);
                if(resultObject != null) {
                    ArrayList<HashMap> arrayList = (ArrayList) resultObject.get("list");
                    if (arrayList != null && arrayList.size() > 0) {
                        for (int i = 0; i < arrayList.size(); i++) {
                            HashMap map = (HashMap) arrayList.get(i);
                            ExtentContentModel model = new ExtentContentModel(map);
                            ExtentContentItemViewVm vm = new ExtentContentItemViewVm();
                            vm.model = model;
                            mal_extentContent.add(vm);
                        }
                        ExtentContentItemViewVm lastVm = (ExtentContentItemViewVm) mal_extentContent.get(mal_extentContent.size() - 1);
                        lastExtentContentId = lastVm.model.id.toString();
                        MenuView_extentContent.reloadData();
                        MenuView_extentContent.finishRefresh(true, arrayList.size()>0);

                    } else {
                        MenuView_extentContent.reloadData();
                        MenuView_extentContent.finishRefresh(true, false);
                    }
                }
                else {
                    MenuView_extentContent.finishRefresh(false,false);
                }

            }
        });
    }

    public static void loadExtendContent(String roomId,String pageSize,String nextPageId, JsRequestDictionaryCallback callback) {
        String urlString = String.format("%s/%s?roomId=%s", JsRequestManager.sharedInstance().serverAddress,"apiserver/listExtendContent.action",roomId);

        HashMap map_param = new HashMap();
        map_param.put("roomID",roomId);
        map_param.put("nextPageID",nextPageId);
        map_param.put("pagesize",pageSize);

        JsRequestManager.sharedInstance().postReqeustByJson(urlString, map_param, callback);
    }
}